package Gamefield;

import java.util.ArrayList;

import Pieces.Piece;

public class Tray {
	private ArrayList<Piece> _capturedPieces;

	public Tray() {
		_capturedPieces = new ArrayList<Piece>();
	}
	
	public Tray(Tray copy) {
		_capturedPieces = new ArrayList<Piece>();
		
		for (Piece p : copy.getCapturedPieces()) {
			_capturedPieces.add(new Piece(p));
		}
	}

	public ArrayList<Piece> getCapturedPieces(){
		return _capturedPieces;
	}
	
	public void setCapturedPieces(ArrayList<Piece> capturedPieces) {
		this._capturedPieces = capturedPieces;
	}
	
	public void add(Piece p){
		_capturedPieces.add(p);
	}

	public Piece usePiece(char fig) {
		for(int i=0;i<_capturedPieces.size();i++) {
			if(_capturedPieces.get(i).getPiecename() == fig){
				return _capturedPieces.remove(i);
			}
		}
		return null;
	}
	
	public boolean hasPiece(char fig) {
		for(int i=0;i<_capturedPieces.size();i++) {
			if(_capturedPieces.get(i).getPiecename() == fig){
				return true;
			}
		}
		return false;
	}
}
